package com.jucai.pppeiyouclient.adapter;

import android.content.Context;
import android.view.View;

import com.jucai.pppeiyouclient.R;
import com.jucai.pppeiyouclient.base.CommonRecyclerViewAdapter;
import com.jucai.pppeiyouclient.bean.ParticipantOrderBean;
import com.jucai.pppeiyouclient.comm.CommonRequestNetData;
import com.jucai.pppeiyouclient.utils.LogUtils;
import com.jucai.pppeiyouclient.view.dialog.RefuseReasonDialog;

import java.util.HashMap;
import java.util.List;

/**
 * Created by Kuky on 2017-05-05.
 */

public class NegParToAgreeAdapter extends CommonRecyclerViewAdapter<ParticipantOrderBean> {
    private static final String TAG = "NegParToAgreeAdapter : ";

    public NegParToAgreeAdapter(Context context, List<ParticipantOrderBean> data) {
        super(context, data);
    }

    @Override
    public void bindHolder(final CommonHolder holder, final ParticipantOrderBean participantOrderBean) {

        holder.setImage(R.id.part_img, participantOrderBean.getMember_avatar(), 80, 80);
        holder.setText(R.id.part_phone, participantOrderBean.getMember_phone());
        holder.setVisible(R.id.to_be_agree);
        holder.setOnclickListener(R.id.part_refuse, new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                final RefuseReasonDialog reasonDialog = new RefuseReasonDialog(mContext);
                reasonDialog.negOrAgree(true);
                reasonDialog.setOnclickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        LogUtils.e(TAG + " : dialog click");
                        String reason = reasonDialog.getReason();

                        HashMap<String, String> param = new HashMap<>();
                        param.put("service", "Conductor_Activity.delapplyuser");
                        param.put("id", participantOrderBean.getAct_order_id());
                        param.put("remark", reason);
                        LogUtils.e(TAG + "param = " + param.toString());
                        CommonRequestNetData.getJsonStringData(mContext, param,true, new CommonRequestNetData.JsonStringCallBack() {
                            @Override
                            public void parseJsonString(String str) {
                                LogUtils.e(TAG + "str = " + str);
                                removeData(participantOrderBean);
                                notifyItemRemoved(getRealPos(holder));
                            }
                        });
                    }
                });
                reasonDialog.show();
            }
        });
        holder.setOnclickListener(R.id.part_agree, new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                HashMap<String, String> agreeParam = new HashMap<>();
                agreeParam.put("id", participantOrderBean.getAct_order_id());
                agreeParam.put("service", "Conductor_Activity.agreeapply");

                CommonRequestNetData.getJsonString(mContext, false, agreeParam, new CommonRequestNetData.JsonStringCallBack() {
                    @Override
                    public void parseJsonString(String str) {
                        LogUtils.e(TAG + str);
                    }
                });

                mData.remove(participantOrderBean);
                notifyItemRemoved(getRealPos(holder));
            }
        });
    }

    @Override
    protected int getItemType(int position) {
        return 0;
    }

    @Override
    public int getLayoutId(int viewType) {
        return R.layout.item_participant_layout;
    }
}
